<?php
// könnte kunde werden :
//http://www.corbismotion.com

//http://www.bunkus.org/videotools/mkvtoolnix/doc/mkvmerge.html
//http://personal.cscs.ch/~mvalle/mencoder/mencoder.html
//http://www.slashcam.de/artikel/Grundlagen/DV-Produktion-in-16-9.html
//http://en.linuxreviews.org/HOWTO_Convert_video_files
//mpgjoin will do the trick
//http://sourceforge.net/projects/videomerge3d/files/
//http://ulyssesonline.com/2009/12/03/concatenate-video-files-using-ffmpeg/
//http://videoencoding.websmith.de/encoding-praxis/linux-ffmpeg-encoding.html
//http://www.longtailvideo.com/support/jw-player/26/web-video-compression

//  -mc 0 -noskip -cache 8192
//exec('mediainfo /home/www/oncut/_software/mediainfo/iphone.mov', $mediainfoContent);
//exec('mediainfo /home/www/oncut/_software/mediainfo/jabhook2.mpg', $mediainfoContent);
//exec('mediainfo /home/www/oncut/_software/mediainfo/GEA-Intro.mov', $mediainfoContent);
//http://www.informatikserver.at/selflinux/html/mplayer11.html


    class mediainfo {


        function getMediaInfo($fullPathToVideo){

            exec('mediainfo '.$fullPathToVideo, $mediainfoContent);


            $arrayVideoInfo = array();
            $getInfos       = "";
            //alle Daten vom Video sammeln /Generell/Video/Audio/
            foreach($mediainfoContent AS $row){

                if(trim($row) == "Video"){
                    $getInfos = "video";
                }
                if(trim($row) == "Audio"){
                    $getInfos = "audio";
                }

                //Video Eckdaten holen
                if($getInfos == "video"){

                    if(preg_match('(Width)', $row)){
                         $arrayVideoInfo['video']['Width'] = trim(preg_replace('(Width|:| |pixels)', '', $row));
                    }
                    //Höhe
                    if(preg_match('(Height)', $row)){
                        $arrayVideoInfo['video']['Height'] = trim(preg_replace('(Height|:| |pixels)', '', $row));
                    }
                    //Bit rate
                    if(preg_match('(Bit rate)', $row)){
                        if(preg_match('(\.)', $row)){
                            $ex = explode('.', $row);
                            $arrayVideoInfo['video']['BitRate'] = trim(preg_replace('(Bit rate|:| |Kbps)', '', $ex[0]))."000";
                        }else{
                            $arrayVideoInfo['video']['BitRate'] = trim(preg_replace('(Bit rate|:| |Kbps)', '', $row))."000";
                        }
                    }
                    //Duration
                    if(preg_match('(Duration)', $row)){
                        $arrayVideoInfo['video']['Duration'] = trim(preg_replace('(Duration|:)', '', $row));
                    }
                    //FrameRate
                    if(preg_match('(Frame rate)', $row)){
                        $arrayVideoInfo['video']['FrameRate'] = trim(preg_replace('(Frame rate|:| |fps)', '', $row));
                    }
                    //Display aspect ratio
                    if(preg_match('(Display aspect ratio)', $row)){
                        $arrayVideoInfo['video']['DisplayAspectRatio'] = trim(preg_replace('(Display aspect ratio|:)', '', $row));
                    }
                    //Color space
                    if(preg_match('(Color space)', $row)){
                        $arrayVideoInfo['video']['ColorSpace'] = trim(preg_replace('(Color space|:)', '', $row));
                    }
                    //Bit depth
                    if(preg_match('(Bit depth)', $row)){
                        $arrayVideoInfo['video']['BitDepth'] = trim(preg_replace('(Bit depth|:)', '', $row));
                    }

                //Audio Eckdaten holen
                }elseif($getInfos == "audio"){

                    //Format
                    if(preg_match('(Format   )', $row)){
                        $arrayVideoInfo['audio']['Format'] = trim(preg_replace('(Format|:)', '', $row));
                    }
                    //Duration
                    if(preg_match('(Duration)', $row)){
                        $arrayVideoInfo['audio']['Duration'] = trim(preg_replace('(Duration|:)', '', $row));
                    }
                    //Duration
                    if(preg_match('(Bit rate)', $row)){
                        $arrayVideoInfo['audio']['BitRate'] = trim(preg_replace('(Bit rate| |:)', '', $row));
                    }
                    //Channel
                    if(preg_match('(Channel\()', $row)){
                        $arrayVideoInfo['audio']['Channel'] = trim(preg_replace('(Channel\(s\)|:|channels|channel)', '', $row));
                    }
                    //Sampling rate
                    if(preg_match('(Sampling rate)', $row)){
                        $arrayVideoInfo['audio']['SamplingRate'] = (int) trim(preg_replace('(Sampling rate|:|KHz|\.)', '', $row))*100;
                    }
                    //Bit depth
                    if(preg_match('(Bit depth)', $row)){
                        $arrayVideoInfo['audio']['BitDepth'] = trim(preg_replace('(Bit depth|:)', '', $row));
                    }

                //Generelle Eckdaten holen
                }else{

                    if($row == 'Format   '){
                        $arrayVideoInfo['general']['Format'] = trim(preg_replace('(Format|:)', '', $row));
                    }
                    if(preg_match('(Format profile)', $row)){
                        $arrayVideoInfo['general']['FormatProfile'] = trim(preg_replace('(Format profile|:)', '', $row));
                    }
                    if(preg_match('(File size)', $row)){
                        $arrayVideoInfo['general']['FileSize'] = trim(preg_replace('(File size|:)', '', $row));
                    }
                    if(preg_match('(Duration)', $row)){
                        $arrayVideoInfo['general']['Duration'] = trim(preg_replace('(Duration|:)', '', $row));
                    }
                    if(preg_match('(Overall bit rate)', $row)){
                        $arrayVideoInfo['general']['OverallBitRate'] = trim(preg_replace('(Overall bit rate|:)', '', $row));
                    }
                    if(preg_match('(Recorded date)', $row)){
                        $arrayVideoInfo['general']['RecordedDate'] = trim(preg_replace('(Recorded date|:)', '', $row));
                    }

                }
            }

            return $arrayVideoInfo;
        }
    }
    //Wichtig bei flv
    // flv does not support that sample rate, choose from (44100, 22050, 11025).

    //Splitten ffmpeg
    //ffmpeg -ss 00:00:40 -t 00:00:50 -i contest1.mkv -acodec copy -vcodec copy smallfile_3.mkv

    //mecoder
    //mencoder -forceidx -of lavf -oac pcm -ovc copy smallfile_1.mp4 smallfile_2.mp4 -o new1.mkv

    //Seitenränder zum video hinzufügen
    //mencoder -forceidx -of lavf -oac pcm -ovc lavc -vf scale=640:480,expand=1280:720 -lavcopts aspect=16/9 contest1.mp4 -o new1.mkv

    //Mencoder join 2 Videos gute quali
    //mencoder -ovc lavc  -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:vbitrate=4570000:acodec=libfaac -oac pcm OUTPUT_1.mp4 OUTPUT_2.mp4 -o complete.mp4

    //High End-Quali mp4 Rendern
    // ffmpeg -i joerg.mov -vcodec libx264 -level 12 -b 128000 -r 25 -bt 144000 -s 240x192 -coder 1 -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method full -subq 7 -me_range 23 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -refs 6 -directpred 2 -trellis 1 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip -f mp4 -acodec libfaac -ab 56000 -ac 2 -ar 48000 OUTPUT.mp4

    /*
    //$origVideo = "/home/www/oncut/_software/mediainfo/iphone.mov";
    $origVideo = " /home/www/oncut/_software/mediainfo/gomex/joerg.mov";
    $path = "/home/www/oncut/_software/mediainfo/";


    ffmpeg
        "-i ".joerg.mov. " ".           //Orginal Video
        "-vcodec ".libx264. " ".        //Videocodec
        "-level ".12. " ".              //Quaili Level
        "-b ".128000. " ".              //Bitrate
        "-r ".25. " ".                  //Framerate
        "-bt ".144000. " ".             //Set video bitrate tolerance (in bits, default 4000k). Has a minimum value of: (target_bitrate/target_framerate). In 1-pass mode, bitrate tolerance specifies how far ratecontrol is willing to deviate from the target average bitrate value. This is not related to min/max bitrate. Lowering tolerance too much has an adverse effect on quality
        "-s ".240x192. " ".             //Videogröße
        "-coder ". 1. " ".
        "-flags +loop ".
        "-cmp +chroma ".
        "-partitions +parti8x8+parti4x4+partp8x8+partb8x8 ".
        "-me_method full ".             //Set motion estimation method to method. Available methods are (from lowest to best quality):
        "-subq ".7. " ".
        "-me_range ". 23. " ".
        "-g ".250. " ".                 //Set the group of pictures size.
        "-keyint_min ".25. " ".
        "-sc_threshold ".40. " ".
        "-i_qfactor ".0.71. " ".
        "-b_strategy ".1. " ".
        "-qcomp ".0.6. " ".
        "-qmin ".10. " ".
        "-qmax ".51. " ".
        "-qdiff ".4. " ".               //maximum difference between the quantizer scales (VBR)
        "-bf ".16. " ".                 //Use ’frames’ B-frames (supported for MPEG-1, MPEG-2 and MPEG-4).
        "-refs ".6. " ".
        "-directpred ".2. " ".
        "-trellis ".1. " ".
        "-flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip ".
        "-f mp4 ".                      //format
        "-acodec libfaac ".
        "-ab ".56000." ".
        "-ac ".2. " ".
        "-ar ".48000. " ".              //Audio Bitrate
        "OUTPUT.mp4";




echo 'ffmpeg -i '.$origVideo.
    ' -s '. $arrayVideoInfo['video']['Width'].
    'x'.   $arrayVideoInfo['video']['Height'].
    ' -deinterlace '.
    ' -ar '. $arrayVideoInfo['audio']['SamplingRate'] .
    ' -r '.  $arrayVideoInfo['video']['FrameRate'].
    ' -b '.  $arrayVideoInfo['video']['BitRate'].
    ' -acodec libmp3lame '.
    ' -ac '.$arrayVideoInfo['audio']['Channel']." ".
    $path.'contest1.flv';


    exec('ffmpeg -i '.$origVideo.
            ' -s '. $arrayVideoInfo['video']['Width'].
            'x'.   $arrayVideoInfo['video']['Height'].
            ' -deinterlace '.
            ' -ar '. $arrayVideoInfo['audio']['SamplingRate'] .
            ' -r '.  $arrayVideoInfo['video']['FrameRate'].
            ' -b '.  $arrayVideoInfo['video']['BitRate'].
            ' -acodec libmp3lame '.
            ' -ac '.$arrayVideoInfo['audio']['Channel']." ".
        $path.'contest1.mkv');


echo "<pre>";
print_r($arrayVideoInfo);
echo "</pre>";*/


?>